﻿namespace Web.Control.WWW.Course
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Model.WWW_User.Teach;
    using BLF.WWW_User.Teach;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using System.Collections.Generic;
    public class EditCourse : BaseControl
    {
        private string memberno = "";
        protected ArrayList arrlist;
        protected int i = 0;
        protected long cid;
        protected List<string> tagList;
        protected CoursesModel cm;
        protected TeachModel tm;

        protected override void OnLoad(EventArgs e)
        {
            memberno = HttpContext.Current.User.Identity.Name;
            if (memberno == "")
            {
                Page.Response.Redirect("/user/login.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri.Split('?')[0]);
                return;
            } if (!string.IsNullOrEmpty(Request["cid"]))
            {
                cid = long.Parse(Request["cid"]);
            }
            else {
                Response.End();
            }
            arrlist= Teach.GetACourse(memberno, cid);
            cm = arrlist[0] as CoursesModel;
            tagList = arrlist[1] as List<string>;
            tm = arrlist[2] as TeachModel;
            if (cm == null||cm.MemberNo==null)
            {
                Response.End();
            }
            base.OnLoad(e);
        }
        protected string fromlevel()
        {
            string level="";
            if (cm.Level != null && cm.Level != "")
            {
                level = cm.Level.Trim().Substring(0, 1);
            }
            return level;
        }
        protected string tolevel()
        {
            string level = "";
            if (cm.Level!=null&&cm.Level.Trim() != "")
            {
                level = cm.Level.Trim().Substring(cm.Level.Length-1, 1);
            }
            return level;
        }
        /// <summary>
        /// 检查是否选择该tag
        /// </summary>
        /// <param name="tag">tag</param>
        /// <returns>bool</returns>
        protected bool TagCheck(string tag)
        {
            for (int i = tagList.Count - 1; i >= 0; i--)
            {
                if (tag == tagList[i])
                {
                    tagList.Remove(tag);
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 取出剩余tag
        /// </summary>
        /// <returns></returns>
        protected string Tags()
        {
            string tag = "";
            for (int i = tagList.Count - 1; i >= 0; i--)
            {
                tag += tagList[i] + " ";
            }
            return tag;
        }
        protected string GetTLang(string TLang)
        {
            string a = "";
            if (TLang != "" && TLang != null&&cm.LanguageLearn != TLang)
            {
                a = "<option value='" + TLang + "'>" + BLF.StaticData.GetLanguageText(TLang) + "</option>";
            }
            return a;
        }
        protected string GetMotherTongue(string MotherTongue)
        {
            string a = "";

            if (MotherTongue != "" && MotherTongue != null&&!(cm.BaseLanguage.IndexOf(MotherTongue)>-1))
            {
                i++;
                a = "<input type='checkbox' value='" + MotherTongue + "' id='che" + i.ToString() + "'/><label for='che" + i.ToString() + "'>" + BLF.StaticData.GetLanguageText(MotherTongue) + "</label>";
            }
            return a;
        }
        protected string GetBaseLanguage()
        {
            string a = "";

            if ( cm.BaseLanguage != null&&cm.BaseLanguage != "")
            {
                int le = cm.BaseLanguage.Split('|').Length;
                for (int j = 0; j<le; j++)
                {
                    if (cm.BaseLanguage.Split('|')[j] != "")
                    {
                        i++;
                        a += "<input type='checkbox' value='" + cm.BaseLanguage.Split('|')[j] + "' id='che" + i.ToString() + "' checked='checked'/><label for='che" + i.ToString() + "'>" + BLF.StaticData.GetLanguageText(cm.BaseLanguage.Split('|')[j]) + "</label>";
                    }
                
                }
            }
            return a;
        }
    }
}